﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：周传雄 
    //
    // 文件名：DistributePlanList.cs
    // 文件功能描述：发票详情查看
    // 创建标识：周传雄2009-05-12
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.Common;

namespace HZ.DrugTrade.Web.Enterprise
{
    public partial class IvoiceDetail : BasePage
    {
        public IvoiceDetail()
        {
            this.ModuleNo = Module.发票管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ShowData();
            }
        }
        private void ShowData()
        {
            IList<Model.View.InvoiceDistribution> ListInvoiceDistribution = new List<Model.View.InvoiceDistribution>();
            Model.Query.InvoiceDistribution qryCondition = new Model.Query.InvoiceDistribution();
            User user = CurrentAccount.GetUser();
            qryCondition.CompanyID_PS = user.Org.OrgID;
            qryCondition.OrderName = txtOrderName.Text.ToString().Trim();
            qryCondition.GoodsName = txtProdcutname.Text.ToString().Trim();
            qryCondition.Material = txtMaterial.Text.ToString().Trim();
            qryCondition.Outlookc = txtOutLookc.Text.ToString().Trim();
            qryCondition.HospitalName = txtHospitalName.Text.ToString().Trim();
            qryCondition.CompanyName_SC = txtCompanyName.Text.Trim();
            qryCondition.PinyinCode = this.txtpinyincode.Text.Trim().ToUpper();
            qryCondition.ProjectID = this.ddlProjectid.SelectedValue;
            qryCondition.DistributeTimeFrom = new HZ.Common.ConvertHelper(txtTimeFrom.Text.ToString().Trim()).ToDateTime;
            qryCondition.DistributeTimeTo = new HZ.Common.ConvertHelper(txtTimeTo.Text.ToString().Trim()).ToDateTime;
            switch (this.ddlstatus.SelectedItem.Value)
            {
                //0未审核；1通过；2不通过
                //改为 0 未提交，1 已提交
                case "":
                    qryCondition.AuditStatus = null;
                    break;
                case "0":
                    qryCondition.AuditStatus = 0;
                    break;
                case "1":
                    qryCondition.AuditStatus = 1;
                    break;
                //case 3:
                //    qryCondition.AuditStatus = 2;
                //    break;
            }
            qryCondition.SortFields = " InvoiceTime desc ";
            //AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            int totalCount = 0;
            IBLL_Purchase iPurchase = Factory.BLL_Purchase();
            ListInvoiceDistribution = iPurchase.GetInvoiceDistributionByWhere(qryCondition, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            AspNetPager1.RecordCount = totalCount;
            gvwInvoiceAdd.DataSource = ListInvoiceDistribution;
            gvwInvoiceAdd.DataBind();
        }
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            ShowData();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            Model.Query.InvoiceDistribution qryCondition = new Model.Query.InvoiceDistribution();
            User user = CurrentAccount.GetUser();
            qryCondition.CompanyID_PS = user.Org.OrgID;
            qryCondition.OrderName = txtOrderName.Text.ToString().Trim();
            qryCondition.GoodsName = txtProdcutname.Text.ToString().Trim();
            qryCondition.Material = txtMaterial.Text.ToString().Trim();
            qryCondition.Outlookc = txtOutLookc.Text.ToString().Trim();
            qryCondition.HospitalName = txtHospitalName.Text.ToString().Trim();
            qryCondition.CompanyName_SC = txtCompanyName.Text.Trim();
            qryCondition.PinyinCode = this.txtpinyincode.Text.Trim().ToUpper();
            qryCondition.ProjectID = this.ddlProjectid.SelectedValue;
            qryCondition.DistributeTimeFrom = new HZ.Common.ConvertHelper(txtTimeFrom.Text.ToString().Trim()).ToDateTime;
            qryCondition.DistributeTimeTo = new HZ.Common.ConvertHelper(txtTimeTo.Text.ToString().Trim()).ToDateTime;
            switch (this.ddlstatus.SelectedItem.Value)
            {
                //0未审核；1通过；2不通过
                //改为 0 未提交，1 已提交
                case "":
                    qryCondition.AuditStatus = null;
                    break;
                case "0":
                    qryCondition.AuditStatus = 0;
                    break;
                case "1":
                    qryCondition.AuditStatus = 1;
                    break;
            }
            qryCondition.SortFields = " InvoiceTime desc ";
            string where = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition<HZ.DrugTrade.Model.Query.InvoiceDistribution>(qryCondition, true);
            string sql = string.Format(@"SELECT OrderName 采购单名称,HospitalName 采购医疗机构,CompanyName_SC 生产企业,GoodsName 产品名称,Outlookc 规格型号,Material 材质,
                                        Unit 单位,Price 采购价格,PurchaseCount 采购数量,Dis_DistributeCount 批配送量,Dis_WarehouseCount 批入库量,BatchRecordID 批号,
                                        DistributeTime 配送时间,case AuditStatus when 0 then '未提交' else '已提交' end as 审核状态 FROM View_InvoiceDistribution WHERE 1=1 {0}", where);
            HZ.DrugTrade.BLL.ExcelHelper.ExportByWeb(HZ.Data.DbHelperFactory.Create().ExecuteTable(sql), "", "发票信息.xls");
        }
    }
}
